package com.jml.ddd.sample.anemicdomainmodel.dao;


import com.jml.ddd.sample.anemicdomainmodel.model.AccountRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AccountRecordDao {
    @Insert("insert into ACCOUNT_RECORD(account_id, amount, type, source_type, source_id, created)"+
            " values(#{r.accountId}, #{r.amount}, #{r.type},  #{r.sourceType}, #{r.sourceId}, #{r.created})")
    int insert(@Param("r") AccountRecord accountRecord);

    @Select("select count(id) from ACCOUNT_RECORD where account_id=#{accountId} and type=#{type} and"+
            " source_type=#{sourceType} and source_id=#{sourceId}")
    boolean exists(@Param("accountId") Integer accountId, @Param("type") int type, @Param("sourceType") int sourceType,
                   @Param("sourceId") String sourceId);
}
